/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.klikmee.sms.core.base.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceException;

import org.springframework.orm.jpa.JpaCallback;

import com.klikmee.sms.core.model.Client;
import com.klikmee.sms.core.model.Service;

/**
 * 
 * @author makcro
 */
public class ServiceDAO extends AbstractDAO<Service>  {
	
	public ServiceDAO() {
		super( Service.class );
	}

	public Service findByName( final String serviceName ) {

		try {
			return (Service) this.entityManager.createNamedQuery( "Service.findByName" ).setParameter( "name", serviceName ).getSingleResult();
		} catch (NoResultException e) {
			return null;
		}
	}
	
	public List<Service> findByClient(Client client){
		return (List<Service>) entityManager.createNamedQuery( "Service.findByClient" ).setParameter( "client", client ).getResultList();
	}

	public List<Service> findRange( int[] range ) {
		throw new UnsupportedOperationException( "Not supported yet." );
	}

	public int count() {
		throw new UnsupportedOperationException( "Not supported yet." );
	}
	
	public List<Service> findAllPrioritized(){
		return entityManager.createNamedQuery( "Service.findAllPrioritized" ).getResultList();
	}
	
}
